package com.example.senior_bug.controller;

import com.example.senior_bug.EntityClass.Address;
import com.example.senior_bug.ToolClass.Result;
import com.example.senior_bug.Service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/Address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    //用户地址页面
    @RequestMapping("/getAllByCustomerName")
    public Result GetAllAddressByCustomerName(@RequestParam String CustomerName) {
        return addressService.getAddressByCustomerName(CustomerName);
    }

    //商家地址页面
    @RequestMapping("/getAllByBusinessName")
    public Result GetAllByBusinessName(@RequestParam String BusinessName) {
        return addressService.getAddressByStoreName(BusinessName);
    }

    //用户或商家添加新地址
    @RequestMapping(value = "/addAddress", method = RequestMethod.POST, produces = "application/json")
    public Result AddAddress(@RequestBody Address address) {
        return addressService.addNewAddress(address);
    }

    //用户或商家修改地址
    @RequestMapping(value = "/modifyAddress", method = RequestMethod.POST, produces = "application/json")
    public Result ModifyAddress(@RequestBody Address address) {
        return addressService.modifyAddress(address);
    }

    //用户或商家删除地址
    @RequestMapping("/deleteAddress")
    public Result DeleteAddress(@RequestParam int id) {
        return addressService.deleteAddress(id);
    }

}
